//
//  XWNetWorkTool.m
//  CGWSWW
//
//  Created by lanou3g on 16/8/16.
//  Copyright © 2016年 CXG. All rights reserved.
//

#import "XWNetWorkTool.h"
#import "XWpromtpTool.h"
#import <AFNetworking.h>
#import <MBProgressHUD.h>


@implementation XWNetWorkTool

+ (void)netWorkToolGetWithUrl:(NSString *)url parameters:(NSDictionary *)parameters response:(void (^)(id))success
{
    [[AFNetworkReachabilityManager sharedManager] startMonitoring];
    [[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        if (status <= 0) {
            [XWpromtpTool promptModeText:@"没有网络了" afterDelay:2];
        }else{
            MBProgressHUD *netPrompt = [XWpromtpTool promptModeIndeterminatetext:@"正在加载中"];
            //加载数据
            AFHTTPSessionManager *manger = [AFHTTPSessionManager manager];
            manger.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/html",@"application/javascript",nil];
            [manger GET:url parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                if (responseObject) {
                    [netPrompt removeFromSuperview];
                    if (success) {
                        success(responseObject);
                    }
                }
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                [netPrompt removeFromSuperview];
                NSLog(@"%@",error);
            }];
        }
    }];
}



@end
